package com.oma.testcase;
import java.io.IOException;
import java.lang.Runtime;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;


public class Upload extends Webdriver {

	
	public void upload(WebDriver driver) throws IOException{
		
	//UPLOADING OF FILES
		
		//Residency Training
		driver.findElement(By.xpath("//input[@id='resDate~0']")).click();
		WebElement resTrain = driver.findElement(By.xpath("//div[@id='residency']/div/div[1]/div[1]/div/div[2]/span/span[1]"));
		Runtime.getRuntime().exec("C:\\Users\\sandy\\Desktop\\newfolder\\stluke\\Java\\workspace_project\\OMA\\AutoIt\\medSchool.exe");
		resTrain.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//Medical School
		driver.findElement(By.xpath("//input[@id='medDate~0']")).click();
		WebElement medSchool = driver.findElement(By.xpath("//div[@id='medSchool']/div/div[1]/div[1]/div/div[2]/span/span[1]"));
		Runtime.getRuntime().exec("C:\\Users\\sandy\\Desktop\\newfolder\\stluke\\Java\\workspace_project\\OMA\\AutoIt\\medSchool.exe");
		medSchool.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
				
		//Specialty Certification
		driver.findElement(By.xpath("//input[@id='speDate~0']")).click();
		WebElement specCert = driver.findElement(By.xpath("//div[@id='specialty']/div/div[1]/div[1]/div/div[2]/span/span[1]"));
		Runtime.getRuntime().exec("C:\\Users\\sandy\\Desktop\\newfolder\\stluke\\Java\\workspace_project\\OMA\\AutoIt\\medSchool.exe");
		specCert.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
				
		//Reference - Head
		driver.findElement(By.xpath("//input[@id='refDate~0']")).click();
		WebElement head = driver.findElement(By.xpath("//div[@id='referenceLetter']/div/div[1]/div[1]/div/div[2]/span/span[1]"));
		Runtime.getRuntime().exec("C:\\Users\\sandy\\Desktop\\newfolder\\stluke\\Java\\workspace_project\\OMA\\AutoIt\\medSchool.exe");
		head.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
				
		//Reference - Peer
		driver.findElement(By.xpath("//input[@id='refDate~1']")).click();
		WebElement peer = driver.findElement(By.xpath("//div[@id='referenceLetter']/div/div[3]/div[1]/div/div[2]/span/span[1]"));
		Runtime.getRuntime().exec("C:\\Users\\sandy\\Desktop\\newfolder\\stluke\\Java\\workspace_project\\OMA\\AutoIt\\medSchool.exe");
		peer.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
	//click upload button
	driver.findElement(By.xpath("//button[@id='uploadBtn']")).click();
	driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);	
	//forward to med sec
	System.out.println(driver.findElement(By.xpath("//div[@class='bar bar-alert']")).getText());
	try{
		WebElement forward = driver.findElement(By.xpath("//button[@id='forwardBtn']"));
		System.out.println("Files Uploaded.");
		forward.click();
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
	}catch(Exception e){
		System.out.println("Unable to upload files.");
	}
	
		//Process process = new ProcessBuilder("C:\\Users\\sandy\\Desktop\\newfolder\\stluke\\Java\\workspace_project\\OMA\\AutoIt\\upload.exe","C:\\Users\\user\\Desktop\\OMA\\Sample Presentation\\BASIC_IP.pdf", "Open").start();
		//Runtime.getRuntime().exec("C:\\Users\\sandy\\Desktop\\newfolder\\stluke\\Java\\workspace_project\\OMA\\AutoIt\\upload.exe");
		//driver.findElement(By.xpath("//input[@id='addDocu~0']")).click();

	}
	
}
